<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h2>历史搜索</h2>
    <input type="text" id = "input">
    
    <div id="app"></div>
    <script>
        var historys = [];
        var input = document.getElementById('input');
        var div = document.getElementById("app");
        input.onkeydown = function(event){
            if(event.keyCode == 13){
                
                
                if(this.value!=''&& historys.indexOf(this.value)==-1){
                    var p = document.createElement('p');
                    p.innerHTML = this.value;
                    div.prepend(p);
                    historys.unshift(this.value);
                    this.value = '';
                    console.log(historys)
                }
                else{
                alert("输入的字段不能为空不能为相同字段");
                this.value = '';
            }
            }
            
        }
    </script>
</body>
</html>